package com.xiaotu.init;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author 张晓
 * @create 2021-07-29 23:44
 */
//@Component
@Order(1) //指定启动顺序
@Slf4j
public class StartOpenOffice implements CommandLineRunner {

    @Override
    public void run(String... args) {
        log.info("LYNK & CO →→→→→→→→→→→→→→→→→→ 开始启动OpenOffice4 ←←←←←←←←←←←←←←←←←← LYNK & CO");
        try {
            // OpenOffice的安装目录
            String OpenOffice_HOME = "D:/OpenOffice4";
            if (OpenOffice_HOME.charAt(OpenOffice_HOME.length() - 1) != '/') {
                OpenOffice_HOME += "/";
            }
            // 启动OpenOffice的服务
            String command = OpenOffice_HOME
                    + "program/soffice.exe -headless -accept=\"socket,host=127.0.0.1,port=8100;urp;\" -nofirststartwizard";
            Runtime.getRuntime().exec(command);
            log.info("LYNK & CO →→→→→→→→→→→→→→→→→→ 启动成功OpenOffice4 ←←←←←←←←←←←←←←←←←← LYNK & CO");
        } catch (IOException e) {
            e.printStackTrace();
            log.error("LYNK & CO →→→→→→→→→→→→→→→→→→ 启动失败OpenOffice4 ←←←←←←←←←←←←←←←←←← LYNK & CO");
        }
    }

}
